
package com.craterhill.java.ems.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.craterhill.java.ems.common.beans.MarkingPeriods;
import com.craterhill.java.ems.dao.impl.AbstractDao;
import com.craterhill.java.ems.dao.utils.EMSResultSetExtractor;

public interface MarkingPeriodDao extends EMSDao<MarkingPeriods> {

	public final String FIELD_LIST = "obj.period_id, obj.session_id, obj.title, obj.from_date, obj.to_date" + AbstractDao.MONITER_FIELDS;

	public final String FIND_MARKING_PERIOD_BY_SESSION = "select " + FIELD_LIST + " from marking_periods obj where obj.session_id = ?";

	public final String SAVE_MARKING_PERIOD = "insert into marking_periods (session_id, title, from_date, to_date, created_by) values (?, ?, ?, ?, ?)";
	public final String DELETE_MARKING_PERIOD = "delete from marking_periods where session_id = ?";

	public List<MarkingPeriods> findBySession(final int sessionId);

	public boolean save(final int sessionId, final List<MarkingPeriods> markingPeriods);

	public final class MarkingPeriodsExtractor extends EMSResultSetExtractor<MarkingPeriods> {

		@Override
		protected MarkingPeriods extractResultSetData(ResultSet resultSet) throws SQLException {
			MarkingPeriods markingPeriods = new MarkingPeriods();
			markingPeriods.setMarkingPeriodId(resultSet.getInt(1));
			markingPeriods.setSessionId(resultSet.getInt(2));
			markingPeriods.setMarkingPeriodTitle(resultSet.getString(3));
			markingPeriods.setMarkingPeriodStartDate(resultSet.getDate(4));
			markingPeriods.setMarkingPeriodEndDate(resultSet.getDate(4));

			markingPeriods.setStatus(resultSet.getBoolean(5));
			markingPeriods.setCreatedBy(resultSet.getInt(6));
			markingPeriods.setCreatedDate(resultSet.getDate(7));
			markingPeriods.setModifiedDate(resultSet.getDate(8));
			return markingPeriods;
		}
	}
}
